﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Stamp_For_Africa_Version_2.Models;

namespace Stamp_For_Africa_Version_2.Repositories
{
	public class PaperRepository
	{

		private StampsDataContext db = new StampsDataContext();
		//
		// Query Methods

		public IQueryable<Paper> FindAllPapers()
		{
			return db.Papers;
		}

		public Paper GetPaper(Guid id)
		{
			Paper paper = db.Papers.SingleOrDefault(d => d.Id == id);
			return paper;
		}

		//
		// Insert/Delete Methods

		public void Add(Paper paper)
		{
			db.Papers.InsertOnSubmit(paper);
			Save();
		}

		public void Delete(Guid id)
		{
			Paper paper = db.Papers.Where(u => u.Id == id).SingleOrDefault();
			if (paper != null)
			{
				db.Papers.DeleteOnSubmit(paper);
				Save();
			}
		}

		public void Save()
		{
			db.SubmitChanges();
		}


	}
}